<template>
  <div>
    <teleport to="body">
      <div class="popup">
        <transition name="fade">
          <div class="popup-mask" v-show="modelValue" @click="closePopup"></div>
        </transition>
        <transition name="offsetY">
          <div class="popup-container" v-bind="$attrs" v-show="modelValue">
            <slot />
          </div>
        </transition>
      </div>
    </teleport>
  </div>
</template>

<script setup>
import { defineEmits } from 'vue'

defineProps({
  modelValue: Boolean
})
const emits = defineEmits(['update:modelValue'])

const closePopup = () => {
  emits('update:modelValue', false)
}
</script>

<style lang="scss" scoped>
.popup {
  &-mask {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 500;
    background-color: #0000003f;
  }
  &-container {
    position: fixed;
    top: 1.3rem;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 500;
    padding: 0.1rem;
    background-color: $light-text-color;
  }
}
</style>
